﻿<%@ Page Language="C#" AutoEventWireup="true" Inherits="cn_member_center_user_address" Codebehind="user_address.aspx.cs" %>
     
<%@ Register Src="../UserControl/header.ascx" TagName="header" TagPrefix="uc1" %>
<%@ Register Src="../UserControl/top_ad.ascx" TagName="top_ad" TagPrefix="uc2" %>
<%@ Register Src="../UserControl/member_menu.ascx" TagName="member_menu" TagPrefix="uc3" %>
<%@ Register Src="../UserControl/footer.ascx" TagName="footer" TagPrefix="uc4" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>收货地址，<%=(new Gift.WebApp.BasicSet()).TitleBind() %></title>
    <meta name="Keywords" content="<%=(new Gift.WebApp.BasicSet()).KeywordBind() %>" />
    <meta name="Description" content="<%=(new Gift.WebApp.BasicSet()).DescriptionBind() %>" />
    <link href="/script/css/public.css" type="text/css" rel="stylesheet" />
    <link href="/script/css/member.css" type="text/css" rel="stylesheet" />
    <link href="/script/css/ie.css" type="text/css" rel="stylesheet" />

    <script type="text/javascript" src="/script/js/jquery-1.6.2.min.js"></script>

    <!--登陆注册 弹出窗口-->
    <style type="text/css" media="all">
        @import "/script/js/login/thickbox.css";
    </style>

    <script src="/script/js/login/thickbox.js" type="text/javascript"></script>
    
    <link href="/script/art_dialog/skins/idialog.css" rel="stylesheet" />

    <script type="text/javascript" src="/script/art_dialog/artDialog.js"></script>

    <script type="text/javascript" src="/script/art_dialog/plugins/iframeTools.source.js"></script>

    <script type="text/javascript" src="/script/js/art_dialog.js"></script>

    <script type="text/javascript">
        $(function () {
            $("#selectProvinces").change(function () {
                $.ajax({
                    type: "POST",
                    url: "/cn/member_center/region.ashx",
                    data: "pid=" + $("#selectProvinces").val(),
                    success: function (msg) {
                        $("#spanCity").html(msg);
                        $("#spProvinces").html("*");
                    }
                });
                return false;
            });
            $("#txtConsignee").blur(function () {
                if ($("#txtConsignee").val() == "")
                    $("#spConsignee").html("<img src=\"/script/images/wrong.gif\" />请输入收货人姓名！");
                else $("#spConsignee").html("<img src=\"/script/images/right.gif\"/>");
                return false;
            });
            $("#selectProvinces").blur(function () {
                if ($("#selectProvinces").val() == "0")
                    $("#spProvinces").html("<img src=\"/script/images/wrong.gif\" />请选择省份/直辖市！");
                else $("#spProvinces").html("<img src=\"/script/images/right.gif\"/>");
                return false;
            });
            $("#txtAddress").blur(function () {
                if ($("#txtAddress").val() == "")
                    $("#spAddress").html("<img src=\"/script/images/wrong.gif\" />请输入详细地址！");
                else $("#spAddress").html("<img src=\"/script/images/right.gif\"/>");
                return false;
            });
            $("#txtZipcode").blur(function () {
                if ($("#txtZipcode").val() == "")
                    $("#spZipcode").html("<img src=\"/script/images/wrong.gif\" />请输入邮政编码！");
                else {
                    if ($("#txtZipcode").val().match(/^[0-9]{6}$/) == null)
                        $("#spZipcode").html("<img src=\"/script/images/wrong.gif\" />邮政编码格式不符！");
                    else $("#spZipcode").html("<img src=\"/script/images/right.gif\"/>");
                }
                return false;
            });
            $("#txtTelephone").blur(function () {
                if ($("#txtTelephone").val() != "") {
                    if ($("#txtTelephone").val().match(/^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/) == null)
                        $("#spTelephone").html("<img src=\"/script/images/wrong.gif\" />电话号码格式不符！如：0754-88888888");
                    else $("#spTelephone").html("<img src=\"/script/images/right.gif\"/>");
                } else $("#spTelephone").html("");
                return false;
            });
            $("#txtMobile").blur(function () {
                if ($("#txtMobile").val() != "") {
                    if (/^13\d{9}$/g.test($("#txtMobile").val()) || (/^15[0-35-9]\d{8}$/g.test($("#txtMobile").val())) || (/^18[05-9]\d{8}$/g.test($("#txtMobile").val())))
                        $("#spMobile").html("<img src=\"/script/images/right.gif\"/>");
                    else
                        $("#spMobile").html("<img src=\"/script/images/wrong.gif\" />手机号码格式不符！");
                } else $("#spMobile").html("");
                return false;
            });
            $("#btnUserAddressSubmit").click(function () {
                if ($("#txtConsignee").val() == "") {
                    $("#txtConsignee").select();
                    $("#spConsignee").html("<img src=\"/script/images/wrong.gif\" />请输入收货人姓名！");
                    return false;
                } else $("#spConsignee").html("<img src=\"/script/images/right.gif\"/>");
                if ($("#selectProvinces").val() == "0") {
                    $("#selectProvinces").focus();
                    $("#spProvinces").html("<img src=\"/script/images/wrong.gif\" />请选择省份/直辖市！");
                    return false;
                } else $("#spProvinces").html("<img src=\"/script/images/right.gif\"/>");
                if ($("#selectCity") != null) {
                    if ($("#selectCity").val() == "0") {
                        $("#selectCity").focus();
                        $("#spProvinces").html("<img src=\"/script/images/wrong.gif\" />请选择市(县/区)！");
                        return false;
                    } else $("#spProvinces").html("<img src=\"/script/images/right.gif\"/>");
                }
                if ($("#txtAddress").val() == "") {
                    $("#txtAddress").select();
                    $("#spAddress").html("<img src=\"/script/images/wrong.gif\" />请输入详细地址！");
                    return false;
                } else $("#spAddress").html("<img src=\"/script/images/right.gif\"/>");
                if ($("#txtZipcode").val() == "") {
                    $("#txtZipcode").select();
                    $("#spZipcode").html("<img src=\"/script/images/wrong.gif\" />请输入邮政编码！");
                    return false;
                } else {
                    if ($("#txtZipcode").val().match(/^[0-9]{6}$/) == null) {
                        $("#txtZipcode").select();
                        $("#spZipcode").html("<img src=\"/script/images/wrong.gif\" />邮政编码格式不符！");
                        return false;
                    } else $("#spZipcode").html("<img src=\"/script/images/right.gif\"/>");
                }
                if ($("#txtTelephone").val() == "" && $("#txtMobile").val() == "") {
                    $("#txtTelephone").select();
                    $("#spTelephone").html("");
                    $("#spMobile").html("<img src=\"/script/images/wrong.gif\" />联系电话和手机号码至少填写一项！");
                    return false;
                }
                else $("#spMobile").html("");
                if ($("#txtTelephone").val() != "") {
                    if ($("#txtTelephone").val().match(/^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/) == null) {
                        $("#txtTelephone").select();
                        $("#spTelephone").html("<img src=\"/script/images/wrong.gif\" />电话号码格式不符！如：0754-88888888");
                        return false;
                    } else $("#spTelephone").html("<img src=\"/script/images/right.gif\"/>");
                } else $("#spTelephone").html("");
                if ($("#txtMobile").val() != "") {
                    if (/^13\d{9}$/g.test($("#txtMobile").val()) || (/^15[0-35-9]\d{8}$/g.test($("#txtMobile").val())) || (/^18[05-9]\d{8}$/g.test($("#txtMobile").val()))) {
                        $("#spMobile").html("<img src=\"/script/images/right.gif\"/>");
                    } else {
                        $("#txtMobile").select();
                        $("#spMobile").html("<img src=\"/script/images/wrong.gif\" />手机号码格式不符！");
                        return false;
                    }
                } else $("#spMobile").html("");
                var region = $("#selectProvinces option:selected").text();
                if ($("#selectCity option:selected").text() != "")
                    region += "," + $("#selectCity option:selected").text();
                var isDefault = $("input[name='isDefault']:checked").val();
                var uaId = $("#hdUserAddress").val();
                $.ajax({
                    type: "POST",
                    url: "user_address.ashx",
                    data: "consignee=" + escape($("#txtConsignee").val()) + "&region=" + escape(region) + "&address=" + escape($("#txtAddress").val()) + "&zipcode=" + $("#txtZipcode").val() + "&telephone=" + $("#txtTelephone").val() + "&mobile=" + $("#txtMobile").val() + "&isDefault=" + isDefault + "&id=" + uaId,
                    success: function (msg) {
                        if (msg == "0") {
                            art.dialog.tips("恭喜您，添加成功！", 1.5);
                            setTimeout("window.location='/cn/member_center/user_address.html'", 2000);
                        } else if (msg == "1") art.dialog.tips("很抱歉，添加失败！", 1.5);
                        else if (msg == "2") {
                            art.dialog.tips("恭喜您，更新成功！", 1.5);
                            setTimeout("window.location='/cn/member_center/user_address.html'", 2000);
                        } else if (msg == "3") art.dialog.tips("很抱歉，更新失败！", 1.5);
                    }
                });
                return false;
            });
        });
    </script>

</head>
<body>
    <uc1:header ID="Header1" runat="server" />
    <uc2:top_ad ID="Top_ad1" runat="server" />
    <div class="container">
        <uc3:member_menu ID="Member_menu1" runat="server" />
        <!--end leftnav-->
        <div class="rightcontent">
            <h5>
                <strong>我的收货地址簿</strong></h5>
            <input class="submit" type="button" value="添加收货地址" onclick="javascript:location.href='/cn/member_center/user_address.html#content';" />
            <table>
                <tr>
                    <th>
                        收货人姓名</th>
                    <th>
                        详细地址</th>
                    <th>
                        邮政编码</th>
                    <th>
                        联系电话</th>
                    <th>
                        手机号码</th>
                    <th>
                        是否默认</th>
                    <th>
                        操作</th>
                </tr>
                <asp:Repeater ID="rptUserAddress" runat="server">
                    <ItemTemplate>
                        <tr>
                            <td>
                                <%# Eval("consignee") %>
                            </td>
                            <td>
                                <%# Eval("address") %>
                            </td>
                            <td>
                                <%# Eval("zipcode") %>
                            </td>
                            <td>
                                <%# Eval("telephone") %>
                            </td>
                            <td>
                                <%# Eval("mobile") %>
                            </td>
                            <td>
                                <%# Convert.ToInt32(Eval("isDefault")) == 1 ? "<strong>默认地址</strong>" : "<a href=\"/cn/member_center/user_address.ashx?uid=" + Eval("id") + "\">设为默认</a>"%>
                            </td>
                            <td>
                                <a href="/cn/member_center/user_address.html?id=<%# Eval("id") %>#content">修改</a><%--<a
                                    href="/member_center/user_address.ashx?did=<%# Eval("id") %>" onclick="confirmMessage('确定要删除吗？');">删除</a>--%>
                                    <a href="javascript:return false;" onclick="confirmMessage('您确定要删除操作吗？','/cn/member_center/user_address.ashx?did=<%# Eval("id") %>');">删除</a>
                                    </td>
                        </tr>
                    </ItemTemplate>
                    <FooterTemplate>
                        <tr style='display: <%# rptUserAddress.Items.Count==0?"block":"none"%>;'>
                            <td colspan="7" style="text-align: center; color: #ff0000;">
                                没有找到任何记录
                            </td>
                        </tr>
                    </FooterTemplate>
                </asp:Repeater>
            </table>
            <div id="content" class="content">
                <form id="formUserAddress" action="" method="post" defaultbutton="btnUserAddressSubmit">
                    <%Response.Write(UserAddressBind()); %>
                    <input id="btnUserAddressSubmit" class="submit" type="submit" value="保存收货地址" />
                </form>
            </div>
        </div>
        <!--end rightcontent-->
        <span class="clear"></span>
    </div>
    <uc4:footer ID="Footer1" runat="server" />
</body>
</html>
